home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 8_6.lha / 8_6 / istream.h < prev    next >
Text File  |  1993-08-08  |  2KB  |  86 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. lass istream
  6.  
  7. friend ostream;
  8.  
  9. streambuf*    bp;
  10. ostream*    tied_to;
  11. char        skipws;        // if non-null, automaticly skip whitespace
  12. short        state;
  13.  
  14. friend void eatwhite (istream&);
  15.  
  16. ublic:
  17. int     skip(int i) { int ii=skipws; skipws=i; return ii; }
  18.  
  19. /*
  20.     formatted input: >> skip whitespace
  21. */
  22. istream& operator>>(char*);            // string
  23. istream& operator>>(char&);            // single character
  24. istream& operator>>(short&);
  25. istream& operator>>(int&);
  26. istream& operator>>(long&);
  27. istream& operator>>(float&);
  28. istream& operator>>(double&);
  29. istream& operator>>(streambuf&);
  30. istream& operator>>(whitespace&);        // skip whitespace
  31. /    istream& operator>>(common&);
  32.  
  33. /*
  34.     raw input: get's do not skip whitespace
  35. */
  36. istream& get(char*, int, char ='\n');        // string
  37. istream& get(streambuf& sb, char ='\n');
  38. istream& get(char& c)                // single character
  39. {
  40.     int os = skipws;
  41.     skipws = 0;
  42.     *this >> c;
  43.     skipws = os;
  44.     return *this;
  45. }
  46.  
  47. istream& putback(char c);
  48. ostream* tie(ostream* s) { ostream* t = tied_to; tied_to = s; return t; }
  49.  
  50.     operator void*(){ return _eof<state?0:this; }
  51. int    operator!()    { return _eof<state; }
  52. int    eof()        { return state&_eof; }
  53. int    fail()        { return _eof<state; }
  54. int    bad()        { return _fail<state; }
  55. int    good()        { return state==_good; }
  56. void    clear(state_value i =0)    { state=i; }
  57. int    rdstate()    { return state; }
  58. /    char*    bufptr()    { return bp->base; }    
  59.  
  60. istream(streambuf* s, int sk =1, ostream* t =0)    // bind to buffer
  61. {
  62.     state = 0;
  63.     skipws = sk;
  64.     tied_to = t;
  65.     bp = s;
  66. }
  67.  
  68. istream(int size, char* p, int sk =1)        // bind to string
  69. {
  70.     state = 0;
  71.     skipws = sk;
  72.     tied_to = 0;
  73.     bp = new streambuf();
  74.     if (p == 0) p = new char[size];
  75.     bp->setbuf(p, size, size);
  76. }
  77.  
  78. istream(FILE *fp, int sk =1, ostream* t =0)    // bind to file
  79. {
  80.     state = 0;
  81.     skipws = sk;
  82.     tied_to = t;
  83.     bp = new filebuf(fp);
  84. }
  85. ;
  86.